package com.restaurant.application.minifacade.data;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;

import java.util.List;

public class GoodsBO implements PickableBean {
    
    public static final String FN_GOODSID = "goodsId";
    public static final String FN_NAME = "name";
    public static final String FN_PRICE = "price";
    public static final String FN_INTEGRAL = "integral";
    public static final String FN_NUMBERLIMIT = "numberLimit";
    public static final String FN_FROMTIME = "fromTime";
    public static final String FN_ENDTIME = "endTime";
    public static final String FN_IMGURL = "imgUrl";
    public static final String FN_DESCRIPTION = "description";
    
    public static final List<String> FIELD_NAMES = Lists.newArrayList(
             FN_GOODSID,
             FN_NAME,
             FN_PRICE,
             FN_INTEGRAL,
            FN_NUMBERLIMIT,
            FN_FROMTIME,
            FN_ENDTIME,
             FN_IMGURL,
             FN_DESCRIPTION);
    
    private String goodsId;
    private String name;
    private String price;
    private Long integral;
    private Integer numberLimit;
    private Long fromTime;
    private Long endTime;
    private String imgUrl;
    private String description;

    public GoodsBO(String goodsId, String name, String price, Long integral, Integer numberLimit, Long fromTime, Long endTime, String imgUrl, String description) {
        setGoodsId(goodsId);
        setName(name);
        setPrice(price);
        setIntegral(integral);
        setNumberLimit(numberLimit);
        setFromTime(fromTime);
        setEndTime(endTime);
        setImgUrl(imgUrl);
        setDescription(description);
    }
    
    public GoodsBO() {
    }
    
    public GoodsBO duplicate() {
        GoodsBO result = new GoodsBO();
        result.goodsId = this.goodsId;
        result.name = this.name;
        result.price = this.price;
        result.integral = this.integral;
        result.numberLimit = this.numberLimit;
        result.fromTime = this.fromTime;
        result.endTime = this.endTime;
        result.imgUrl = this.imgUrl;
        result.description = this.description;
        return result;
    }
    
    @Override
    public String toString() {
        return Convert.toJson(this);
    }
    
    public String getGoodsId() {
        return goodsId;
    }
    
    public void  setGoodsId(String value) {
        this.goodsId = value;
    }
    
    public GoodsBO withGoodsId(String value) {
        setGoodsId(value);
        return this;
    }
    
    public GoodsBO withGoodsId(String value, String defaultValue) {
        setGoodsId(value == null ? defaultValue : value);
        return this;
    }
    
    public String getName() {
        return name;
    }
    
    public void  setName(String value) {
        this.name = value;
    }
    
    public GoodsBO withName(String value) {
        setName(value);
        return this;
    }
    
    public GoodsBO withName(String value, String defaultValue) {
        setName(value == null ? defaultValue : value);
        return this;
    }
    
    public String getPrice() {
        return price;
    }
    
    public void  setPrice(String value) {
        this.price = value;
    }
    
    public GoodsBO withPrice(String value) {
        setPrice(value);
        return this;
    }
    
    public GoodsBO withPrice(String value, String defaultValue) {
        setPrice(value == null ? defaultValue : value);
        return this;
    }
    
    public Long getIntegral() {
        return integral;
    }
    
    public void  setIntegral(Long value) {
        this.integral = value;
    }
    
    public GoodsBO withIntegral(Long value) {
        setIntegral(value);
        return this;
    }
    
    public GoodsBO withIntegral(Long value, Long defaultValue) {
        setIntegral(value == null ? defaultValue : value);
        return this;
    }

    public Integer getNumberLimit() {
        return numberLimit;
    }

    public void setNumberLimit(Integer value) {
        this.numberLimit = value;
    }

    public GoodsBO withNumberLimit(Integer value) {
        setNumberLimit(value);
        return this;
    }

    public GoodsBO withNumberLimit(Integer value, Integer defaultValue) {
        setNumberLimit(value == null ? defaultValue : value);
        return this;
    }

    public Long getFromTime() {
        return fromTime;
    }

    public void setFromTime(Long value) {
        this.fromTime = value;
    }

    public GoodsBO withFromTime(Long value) {
        setFromTime(value);
        return this;
    }

    public GoodsBO withFromTime(Long value, Long defaultValue) {
        setFromTime(value == null ? defaultValue : value);
        return this;
    }

    public Long getEndTime() {
        return endTime;
    }

    public void setEndTime(Long value) {
        this.endTime = value;
    }

    public GoodsBO withEndTime(Long value) {
        setEndTime(value);
        return this;
    }

    public GoodsBO withEndTime(Long value, Long defaultValue) {
        setEndTime(value == null ? defaultValue : value);
        return this;
    }
    
    public String getImgUrl() {
        return imgUrl;
    }
    
    public void  setImgUrl(String value) {
        this.imgUrl = value;
    }
    
    public GoodsBO withImgUrl(String value) {
        setImgUrl(value);
        return this;
    }
    
    public GoodsBO withImgUrl(String value, String defaultValue) {
        setImgUrl(value == null ? defaultValue : value);
        return this;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void  setDescription(String value) {
        this.description = value;
    }
    
    public GoodsBO withDescription(String value) {
        setDescription(value);
        return this;
    }
    
    public GoodsBO withDescription(String value, String defaultValue) {
        setDescription(value == null ? defaultValue : value);
        return this;
    }
    
    public Object getValueOf(String name) {
        switch(name) {
        case "goodsId": return getGoodsId();
        case "name": return getName();
        case "price": return getPrice();
        case "integral": return getIntegral();
            case "numberLimit":
                return getNumberLimit();
            case "fromTime":
                return getFromTime();
            case "endTime":
                return getEndTime();
        case "imgUrl": return getImgUrl();
        case "description": return getDescription();
        }
        return null;
    }
    
    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }
    
    @Override
    public int hashCode() {
        return signature().hashCode();
    }
    
    @Override
    public boolean equals(Object o) {
        if(!(o instanceof GoodsBO)) return false;
        return signature().equals(((GoodsBO)o).signature());
    }
    
    public String signature() {
        throw new RuntimeException("Bean GoodsBO has no signature defined, no hash code or equals possible.");
    }
}
